package com.shen.modules.sys.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.shen.common.utils.Constant;
import com.shen.common.utils.PageUtils;
import com.shen.common.utils.Query;
import com.shen.modules.sys.dao.SysMonitorDao;
import com.shen.modules.sys.entity.SysMonitorEntity;
import com.shen.modules.sys.service.SysMonitorService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author sjl
 */
@Service("sysMonitorService")
public class SysMonitorServiceImpl extends ServiceImpl<SysMonitorDao, SysMonitorEntity> implements SysMonitorService {
    @Autowired
    private SysMonitorDao sysMonitorDao;

    /**
     * 上报错误信息
     * @param sysMonitor
     */
    @Override
    public void reportMonitorService(SysMonitorEntity sysMonitor) {
        sysMonitorDao.reportMonitor(sysMonitor);
    }

    /**
     * 条件查询错误信息
     * @param params
     */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String system = (String)params.get("system");

        Page<SysMonitorEntity> page = this.selectPage(
                new Query<SysMonitorEntity>(params).getPage(),
                new EntityWrapper<SysMonitorEntity>()
                        .like(StringUtils.isNotBlank(system),"system", system)
                        .addFilterIfNeed(params.get(Constant.SQL_FILTER) != null, (String)params.get(Constant.SQL_FILTER))
        );

        return new PageUtils(page);
    }
}
